<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2023/8/7
 * Time: 9:24
 */

namespace app\index\model;


use think\Model;

class WxOrder extends Model
{

    /*
     * 10：待付款；20：带发货；21：部分发货；30：待收货；100：完成；200：全部商品售后之后，订单取消；250：未付款用户主动取消或超时未付款订单自动取消
     * */
    public function getStatusAttr($value)
    {
        $status = [
            10=>'待付款',
            20=>'带发货',
            21=>'部分发货',
            30=>'待收货',
            100=>'完成',
            200=>'全部商品售后之后，订单取消',
            250=>'未付款用户主动取消或超时未付款订单自动取消'
        ];
        return $status[$value];
    }

    public function where_sql($map){
        if(!empty($map['status'])){
            $where['status']=['in',explode(',',$map['status'])];
        }
        if(!empty($map['order_id'])){
            $where['order_id']=$map['order_id'];
        }
        if(isset($map['starttime']) && isset($map['endtime'])){
            if($map['starttime']>$map['endtime'])apiReturn(400,'查询开始日期不能大于结束日期');
            if (!empty($map['starttime']) && !empty($map['endtime'])) {
                $where['create_time']=['between',[strtotime($map['starttime']),strtotime($map['endtime'])]];
            }
        }
        if(!empty($map['title'])){
            $where['product_infos']=['like',"%".$map['title'].'%'];
        }
        if(!empty($map['phone'])){
            $where['virtual_order_tel_number']=$map['phone'];
        }
        //客户备注
        if(!empty($map['merchant_notes'])){
            $where['merchant_notes']=['like',"%".$map['merchant_notes'].'%'];
        }
        if(!empty($map['commissionInfo'])){
            $where['commissionInfo']=['like',"%".$map['commissionInfo'].'%'];
        }
        if(isset($where)){
           return $this->where($where);
        }else{
            return $this;
        }
    }
}